package com.brian.hystrix.web.controller;

import com.brian.hystrix.web.model.CommonResponse;
import com.brian.hystrix.web.model.ConfigInfoResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/all")
public class ConfigController {
	
	private static final Logger logger = LoggerFactory.getLogger(ConfigController.class);

	
	@RequestMapping(value = "/config", method = RequestMethod.GET)
	public ConfigInfoResponse getConfigInfo(HttpServletRequest request) {
		ConfigInfoResponse configInfoResponse = new ConfigInfoResponse();
		try {
			Map<String, Object> configMap = new HashMap<String, Object>();
			CommonResponse commonResponse = new CommonResponse();
			commonResponse.setSuccess(Boolean.TRUE);
			configInfoResponse.setCommonResponse(commonResponse);
			configInfoResponse.setConfigMap(configMap);
		} catch (Exception e) {
			logger.error("getConfigInfo Exception:{}", e.getMessage(), e);
			CommonResponse commonResponse = new CommonResponse();
			commonResponse.setSuccess(Boolean.FALSE);
			commonResponse.setErrorDesc(e.getMessage());
			configInfoResponse.setCommonResponse(commonResponse);
		}
		return configInfoResponse;
	}

}
